Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: reward aggregator #875

Merged
merged 11 commits into from
Oct 14, 2024
Merged

feat: reward aggregator #875

merged 11 commits into from
Oct 14, 2024

Conversation

Marchand-Nicolas
Copy link
Collaborator

@Marchand-Nicolas Marchand-Nicolas commented Oct 13, 2024

close: #858

Summary by CodeRabbit

  • New Features

    • Enhanced ClaimModal component for improved blockchain interaction and responsiveness.
    • Introduced a new function to fetch real rewards data from an API.
    • Updated defiTable component to manage user account information effectively.
  • Bug Fixes

    • Improved loading state management for the "Claim all" button.
  • Documentation

    • Updated TypeScript type definitions for better clarity and structure.
  • Chores

    • Refined component structure and type declarations for consistency.

@Marchand-Nicolas Marchand-Nicolas added the 🔥 Ready for review This pull request needs a review label Oct 13, 2024
Copy link

vercel bot commented Oct 13, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
sepolia-starknet-quest ✅ Ready (Inspect) Visit Preview 💬 Add feedback Oct 14, 2024 0:18am
starknet-quest ✅ Ready (Inspect) Visit Preview 💬 Add feedback Oct 14, 2024 0:18am

Copy link
Contributor

coderabbitai bot commented Oct 13, 2024

Walkthrough

The pull request introduces significant enhancements to the ClaimModal component, improving its functionality for claiming rewards. It includes the addition of new hooks for account management and contract interaction, updates to TypeScript types, and the implementation of a new getRewards function for fetching rewards data. The component's rendering logic has been modified to dynamically display rewards, and the claiming process has been streamlined through direct contract calls. Overall, these changes facilitate better interaction with blockchain data.

Changes

File Change Summary
components/discover/claimModal.tsx Enhanced ClaimModal with new hooks, state variables, and dynamic rendering of rewards. Updated TypeScript types and function signatures.
components/discover/defiTable.tsx Updated defiTable for user account management with new hooks and state management for reward claiming. Minor formatting changes.
services/apiService.ts Introduced getRewards function for fetching rewards data from an API endpoint. Added Call type import.
types/backTypes.d.ts Added new types: Reward, RewardsPerProtocol, and Call. Updated existing types for better formatting.
types/frontTypes.d.ts Added new Call type and reformatted StepMap type definition.

Assessment against linked issues

Objective Addressed Explanation
Claim all rewards with a single button (#858)

Possibly related PRs

  • feat: add claim reward flow #870: Enhancements to the ClaimModal component, focusing on reward management and modal functionality, closely related to the changes made in this PR.

Suggested labels

🚧 In progress do not merge


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between efecc72 and fab8db6.

📒 Files selected for processing (1)
  • components/discover/defiTable.tsx (8 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • components/discover/defiTable.tsx

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 6

🧹 Outside diff range and nitpick comments (5)
types/backTypes.d.ts (4)

494-502: LGTM! Consider consistent formatting for improved readability.

The changes to CreateCustomApi type look good. The addition of optional api_url and regex properties provides more flexibility for API creation. The formatting changes improve readability.

For consistency, consider adding a trailing comma after the last property:

export type CreateCustomApi = {
  quest_id: number;
  name: string;
  desc: string;
  href: string;
  cta: string;
  api_url?: string;
  regex?: string;
};

This style is often preferred in TypeScript as it makes future additions easier and produces cleaner diffs.


504-512: LGTM! Consider consistent formatting for improved readability.

The changes to UpdateCustomApi type look good. The formatting improvements and the addition of optional properties are consistent with the changes made to CreateCustomApi.

For consistency, consider adding a trailing comma after the last property:

export type UpdateCustomApi = {
  id: number;
  name?: string;
  desc?: string;
  href?: string;
  cta?: string;
  api_url?: string;
  regex?: string;
};

This style is often preferred in TypeScript as it makes future additions easier and produces cleaner diffs.


514-517: LGTM! Consider adding a clarifying comment for amount.

The new Reward type looks good and appropriately represents a reward with an amount and a token symbol.

Consider adding a comment to explain why amount is a string instead of a number. This could help prevent confusion for other developers:

export type Reward = {
  // amount is a string to preserve precision for large or small numbers
  amount: string;
  token_symbol: string;
};

This clarification can be particularly helpful in cryptocurrency contexts where precise representation of values is crucial.


519-530: LGTM! Consider using a more flexible structure for RewardsPerProtocol.

Both the RewardsPerProtocol and Call types look good and are well-structured for their purposes. The Call type, in particular, aligns well with the PR objective of implementing a feature to aggregate rewards.

For RewardsPerProtocol, consider using a more flexible structure that allows for easy addition of new protocols in the future:

export type RewardsPerProtocol = {
  [protocol: string]: Reward[];
};

This change would make the type more maintainable as it wouldn't require modification every time a new protocol is added. It also aligns well with the dynamic nature of the DeFi ecosystem.

The Call type is well-defined and appropriate for representing contract calls.

services/apiService.ts (1)

416-434: LGTM: New getRewards function implemented correctly with room for improvements.

The getRewards function is well-implemented and aligns with the PR objective of aggregating rewards for users. It correctly fetches and processes the rewards data. However, consider the following suggestions for improvement:

  1. Add input validation for the address parameter.
  2. Handle potential empty or invalid responses from the API.
  3. Consider using TypeScript type annotations for the function parameters and return type to enhance type safety.

Here's a suggested implementation with these improvements:

export const getRewards = async (address: string): Promise<{ rewards: any, calls: { contractAddress: string, entrypoint: string, calldata: string[] }[] } | null> => {
  if (!address || typeof address !== 'string') {
    console.error('Invalid address provided');
    return null;
  }

  try {
    const response = await fetch(`${baseurl}/defi/rewards?addr=${address}`);
    if (!response.ok) {
      throw new Error(`HTTP error! status: ${response.status}`);
    }
    const data = await response.json();
    if (!data || !data.rewards || !Array.isArray(data.calls)) {
      console.error('Invalid response structure');
      return null;
    }
    const rewards = data.rewards;
    const parsedCalls = data.calls.map((call: Call) => ({
      contractAddress: call.contractaddress,
      entrypoint: call.entrypoint,
      calldata: call.calldata,
    }));
    return { rewards, calls: parsedCalls };
  } catch (err) {
    console.error("Error while fetching rewards", err);
    return null;
  }
};

This implementation includes input validation, better error handling, and type annotations. It also uses console.error for logging errors, which is more appropriate for error messages.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 2f12e15 and be3bade.

⛔ Files ignored due to path filters (1)
  • public/nostra/favicon.ico is excluded by !**/*.ico
📒 Files selected for processing (4)
  • components/discover/claimModal.tsx (4 hunks)
  • services/apiService.ts (2 hunks)
  • types/backTypes.d.ts (2 hunks)
  • types/frontTypes.d.ts (2 hunks)
🧰 Additional context used
🪛 Biome
components/discover/claimModal.tsx

[error] 188-188: Unnecessary use of boolean literals in conditional expression.

Simplify your code by directly assigning the result without using a ternary operator.
If your goal is negation, you may use the logical NOT (!) or double NOT (!!) operator for clearer and concise code.
Check for more details about NOT operator.
Unsafe fix: Remove the conditional expression with

(lint/complexity/noUselessTernary)

🔇 Additional comments (5)
types/frontTypes.d.ts (2)

345-349: LGTM: New Call type aligns with PR objectives

The new Call type is well-defined and follows TypeScript best practices. It provides a clear structure for representing contract calls, which is crucial for implementing the reward aggregation feature. This type will likely be used in the process of claiming rewards across different protocols, supporting the main objective of the PR.


320-320: LGTM: Improved formatting for StepMap type

The formatting change to the last union member of the StepMap type improves consistency and readability. While this change doesn't directly relate to the PR objectives, it contributes to overall code quality.

types/backTypes.d.ts (1)

Line range hint 1-530: Overall, the changes look good and align well with the PR objectives.

The modifications and additions to the type definitions in types/backTypes.d.ts provide a solid foundation for implementing the reward aggregation feature. The new types (Reward, RewardsPerProtocol, and Call) directly support this objective, while the updates to existing types (CreateCustomApi and UpdateCustomApi) improve flexibility and readability.

The suggestions provided in the review are minor and focus on improving maintainability and clarity. These include:

  1. Using more specific types where possible (e.g., for calls in CreateContract)
  2. Consistent formatting (adding trailing commas)
  3. Adding clarifying comments
  4. Using a more flexible structure for RewardsPerProtocol

Implementing these suggestions would further enhance the robustness and maintainability of the codebase. Great work on laying the groundwork for the reward aggregation feature!

services/apiService.ts (2)

28-28: LGTM: Import statement updated correctly.

The addition of the Call type to the import statement is appropriate and consistent with its usage in the new getRewards function. This change enhances type safety for the call objects processed in the function.


Line range hint 1-434: Summary: Changes align well with PR objectives, with minor suggestions for improvement.

The additions to services/apiService.ts effectively implement the reward aggregation feature described in the PR objectives. The new getRewards function provides a mechanism to fetch and process user rewards, which is crucial for the "Claim all" functionality mentioned in the linked issue #858.

The implementation is generally sound, with consistent error handling and appropriate data processing. The suggestions provided for improving input validation, error handling, and type safety in the getRewards function will further enhance the robustness of this feature.

These changes contribute significantly to the goal of streamlining the reward claiming process for users across various Starknet protocols, as outlined in the PR objectives.

types/backTypes.d.ts Show resolved Hide resolved
components/discover/claimModal.tsx Outdated Show resolved Hide resolved
components/discover/claimModal.tsx Outdated Show resolved Hide resolved
components/discover/claimModal.tsx Outdated Show resolved Hide resolved
components/discover/claimModal.tsx Outdated Show resolved Hide resolved
components/discover/claimModal.tsx Outdated Show resolved Hide resolved
Marchand-Nicolas and others added 4 commits October 13, 2024 22:16
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between be3bade and 408d685.

📒 Files selected for processing (1)
  • components/discover/claimModal.tsx (4 hunks)
🧰 Additional context used
🔇 Additional comments (7)
components/discover/claimModal.tsx (7)

13-16: LGTM: New imports for Starknet integration

The added imports for Starknet-related hooks, types, and utilities are appropriate for the new functionality of fetching and managing rewards.


19-21: LGTM: Updated type definitions

The changes to RewardItem and CurrencyRowProps types, using semicolons for property separation, align with TypeScript conventions and accurately reflect the data structure used in the component.

Also applies to: 26-26


34-63: LGTM: Improved RewardComponent structure and styling

The RewardComponent has been updated with better semantic HTML and CSS classes, improving its structure and styling. The use of the AppIcon component with custom styling enhances the visual representation of each reward item.


66-76: LGTM: Enhanced CurrencyRow component

The CurrencyRow component has been updated to use the new CurrencyRowProps type and now includes formatting for large currency values (>= 1000) using the 'K' suffix. This improves readability and follows React best practices.


86-91: LGTM: Updated ClaimModal state and Starknet hooks

The addition of rewards and calls state variables, along with the use of useAccount and useContractWrite hooks from Starknet, provides the necessary functionality for managing fetched rewards data and interacting with the blockchain.


Line range hint 1-199: Overall assessment: Well-implemented reward aggregation feature

The changes in this file successfully implement the reward aggregation feature, aligning well with the PR objectives. Key improvements include:

  1. Integration with Starknet for blockchain interactions.
  2. Dynamic rendering of rewards from multiple protocols.
  3. Updated UI components for better user experience.

The code is generally well-structured and follows React and TypeScript best practices. A few minor suggestions have been made to enhance error handling and simplify the rendering logic.

Great job on implementing this feature! Once the suggested improvements are addressed, this implementation will provide a robust solution for users to view and claim their rewards across multiple Starknet protocols.


93-100: ⚠️ Potential issue

Add error handling for getRewards API call

While the useEffect hook correctly fetches rewards when the address is available, it lacks error handling. This could lead to unhandled exceptions if the API call fails.

Consider adding a try-catch block or using the .catch() method to handle potential errors:

useEffect(() => {
  if (!address) return;
  getRewards(address)
    .then((res) => {
      setRewards(res?.rewards);
      setCalls(res?.calls);
      setLoading(false);
    })
+   .catch((error) => {
+     console.error("Error fetching rewards:", error);
+     showNotification("Failed to fetch rewards", "error");
+     setLoading(false);
+   });
}, [address]);

This ensures that any API errors are logged, the user is notified, and the loading state is properly managed.

Likely invalid or redundant comment.

components/discover/claimModal.tsx Outdated Show resolved Hide resolved
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🧹 Outside diff range and nitpick comments (1)
components/discover/claimModal.tsx (1)

Line range hint 124-173: Fix mismatched JSX tags to resolve parsing errors

There are missing closing tags for the <div> and <Loading> components, leading to parsing errors reported by the static analysis tools.

Ensure that every opening tag has a corresponding closing tag. Here's how you can fix it:

Add the closing tag for the <div> opened at line 124 and the <Loading> component opened at line 127:

...
  • Line 171: Close the <Loading> component.
  • Line 172: Close the <div> opened at line 124.

This ensures proper nesting of JSX elements and resolves the parsing errors.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 408d685 and fdbd153.

📒 Files selected for processing (1)
  • components/discover/claimModal.tsx (4 hunks)
🧰 Additional context used
🪛 Biome
components/discover/claimModal.tsx

[error] 127-127: Expected corresponding JSX closing tag for 'Loading'.

Opening tag

closing tag

(parse)


[error] 124-126: Expected corresponding JSX closing tag for 'div'.

Opening tag

closing tag

(parse)

components/discover/claimModal.tsx Outdated Show resolved Hide resolved
components/discover/claimModal.tsx Show resolved Hide resolved
Copy link
Contributor

@fricoben fricoben left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test E2E

  • When no rewards I have no message, I think you can check for rewards when arriving on the page and make the button available only if rewards are to be claimed
Capture d’écran 2024-10-14 à 08 09 15
  • Infinite loading when no wallet is connected, I think you can juste delete the option to click on the button if there is address
Capture d’écran 2024-10-14 à 08 09 31

@fricoben fricoben added ❌ Change request Change requested from reviewer and removed 🔥 Ready for review This pull request needs a review labels Oct 14, 2024
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

🧹 Outside diff range and nitpick comments (2)
components/discover/claimModal.tsx (2)

34-75: Improved component definitions with better type safety

The RewardComponent and CurrencyRow have been updated to use the FunctionComponent type and the revised type definitions. This enhances type safety and improves the overall structure of the components.

One minor suggestion:

Consider using the more concise arrow function syntax for CurrencyRow:

const CurrencyRow: FunctionComponent<CurrencyRowProps> = ({
  currencyName,
  currencyValue,
}) => (
  // ... component body ...
);

This change would make the syntax consistent with the RewardComponent.


Line range hint 79-193: Overall implementation successfully achieves PR objectives

The updated ClaimModal component effectively implements the reward aggregator feature, aligning well with the PR objectives. Key achievements include:

  1. Integration with Starknet using appropriate hooks.
  2. Fetching and displaying rewards from multiple protocols.
  3. Implementing a "Claim all" functionality.

These changes significantly enhance the user experience by allowing users to view and claim all their rewards in one action, as outlined in the linked issue #858.

While the core functionality is well-implemented, consider addressing the following points to further improve the component:

  1. Enhance error handling in the useEffect hook for reward fetching.
  2. Remove sensitive data from error logging in the doClaimRewards function.
  3. Optimize the reward rendering logic for better performance and readability.
  4. Ensure proper loading state management throughout the component.

To further improve the component's modularity and maintainability, consider:

  1. Extracting the reward fetching logic into a custom hook.
  2. Creating a separate utility function for formatting reward values.
  3. Implementing a more robust error handling strategy throughout the component.

These architectural improvements will make the code more maintainable and easier to test in the future.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between fdbd153 and c73abf4.

📒 Files selected for processing (1)
  • components/discover/claimModal.tsx (4 hunks)
🧰 Additional context used
🔇 Additional comments (2)
components/discover/claimModal.tsx (2)

13-16: New imports enhance functionality and type safety

The addition of these imports indicates a shift towards more robust blockchain integration:

  • useAccount and useContractWrite from @starknet-react/core suggest improved Starknet integration.
  • RewardsPerProtocol type import enhances type safety.
  • getRewards and gweiToEth imports indicate the implementation of reward fetching and conversion logic.

These changes align well with the PR objective of implementing a reward aggregator feature.


19-21: Improved type definitions enhance code clarity

The updates to RewardItem and CurrencyRowProps types, including the use of semicolons for property separation, improve code consistency and readability. This change aligns with TypeScript best practices.

Also applies to: 26-26

components/discover/claimModal.tsx Outdated Show resolved Hide resolved
components/discover/claimModal.tsx Outdated Show resolved Hide resolved
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 5

🧹 Outside diff range and nitpick comments (2)
components/discover/defiTable.tsx (2)

330-330: LGTM with suggestion: Consider adding user feedback for disconnected state.

The addition of the address check before showing the claim modal is a good practice. It prevents the modal from appearing when the user is not connected.

However, consider providing visual feedback or a tooltip for users who aren't connected. This could improve the user experience by clearly indicating why the button might not be clickable.

Would you like me to suggest an implementation for this feedback mechanism?


Line range hint 1-504: Overall assessment: Implementation aligns with PR objectives, with minor suggestions for improvement.

The changes successfully implement the core functionality for aggregating rewards, as outlined in the PR objectives. The integration of the user's account address and the updated "Claim all" button behavior contribute to a more robust user experience.

To further enhance the implementation, consider the following suggestions:

  1. Implement visual feedback for users who aren't connected when they attempt to use the "Claim all" button.
  2. Add error handling for scenarios where the account address might be undefined or null.
  3. Consider adding a loading state for the "Claim all" button while the modal is being prepared to open.

These improvements would further enhance the user experience and make the feature more resilient.

Would you like assistance in implementing any of these suggestions?

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between c73abf4 and efecc72.

📒 Files selected for processing (2)
  • components/discover/claimModal.tsx (4 hunks)
  • components/discover/defiTable.tsx (8 hunks)
🧰 Additional context used
🔇 Additional comments (6)
components/discover/defiTable.tsx (6)

39-39: LGTM: Import statement for useAccount added correctly.

The import of useAccount from @starknet-react/core is appropriately placed and will allow access to the user's account information, which is essential for the new functionality being implemented.


251-252: LGTM: useAccount hook implemented correctly.

The useAccount hook is properly used to extract the user's address. This implementation aligns with the PR objective of enhancing user-specific functionality for claiming rewards.


331-332: Minor formatting changes noted.

The adjustments to the className are minor and appear to be for code style consistency. These changes don't affect functionality and are acceptable.


423-430: Minor formatting changes noted in table header onClick handler.

The adjustments to the onClick handler and the flexRender function call are minor and appear to be for code style consistency. These changes don't affect functionality and are acceptable.


445-450: Minor formatting changes noted in table row onClick handler.

The adjustments to the onClick handler for the table row are minor and appear to be for code style consistency. These changes don't affect functionality and are acceptable.


476-478: LGTM: Improved pagination control styles.

The updates to the style props for the pagination controls enhance the user experience by providing clear visual feedback when pagination is not possible. This is a good improvement in terms of usability.

Also applies to: 490-490

setLoading(false);
closeModal();
showSuccess();
} catch (error) {
setLoading(false);
showNotification("Error while claiming rewards", "error");
console.log("Error while claiming rewards", error);
console.log("Error while claiming rewards", error, calls);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Avoid logging sensitive data in the console

Including calls in the console log may expose sensitive information. It's recommended to log only the error.

Apply this diff to remove calls from the log statement:

- console.log("Error while claiming rewards", error, calls);
+ console.log("Error while claiming rewards", error);
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
console.log("Error while claiming rewards", error, calls);
console.log("Error while claiming rewards", error);

getClaimRewards();
}
}, [open, getClaimRewards]);
}, [calls]);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Update dependency array to include all external dependencies

The dependency array for doClaimRewards is missing some external variables used within the function. This may lead to stale closures if those variables change.

Apply this diff to include all necessary dependencies:

- }, [calls]);
+ }, [calls, execute, closeModal, showSuccess]);
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
}, [calls]);
}, [calls, execute, closeModal, showSuccess]);

Comment on lines +93 to +105
useEffect(() => {
if (!address) return;
getRewards(address)
.then((res) => {
setRewards(res?.rewards);
setCalls(res?.calls);
setLoading(false);
})
.catch((error) => {
showNotification("Error while fetching rewards", "error");
console.log("Error while fetching rewards", error);
});
}, [address]);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Ensure loading state is properly managed in error scenarios

In the useEffect hook, if an error occurs while fetching rewards, the setLoading(false) function is not called. This may cause the loading spinner to remain indefinitely.

Apply this diff to set the loading state in the catch block:

  .catch((error) => {
    showNotification("Error while fetching rewards", "error");
    console.log("Error while fetching rewards", error);
+   setLoading(false);
  });
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
useEffect(() => {
if (!address) return;
getRewards(address)
.then((res) => {
setRewards(res?.rewards);
setCalls(res?.calls);
setLoading(false);
})
.catch((error) => {
showNotification("Error while fetching rewards", "error");
console.log("Error while fetching rewards", error);
});
}, [address]);
useEffect(() => {
if (!address) return;
getRewards(address)
.then((res) => {
setRewards(res?.rewards);
setCalls(res?.calls);
setLoading(false);
})
.catch((error) => {
showNotification("Error while fetching rewards", "error");
console.log("Error while fetching rewards", error);
setLoading(false);
});
}, [address]);

components/discover/claimModal.tsx Show resolved Hide resolved
components/discover/claimModal.tsx Show resolved Hide resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🔥 Ready for review This pull request needs a review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Claim all your rewards
2 participants